<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use app\models\Attention;

/* @var $this yii\web\View */
/* @var $model app\models\Qa */

$this->title = $question->title;
$this->params['breadcrumbs'][] = ['label' => '问答', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="qa-view">

    <h3><?php echo Html::encode($this->title) ?></h3>
    <p>
        <img src="<?php echo $author->avatar ? $author->avatar : '/images/default/avatar.jpg' ?>" width="25" height="25"/>
        &nbsp;&nbsp;<a href="/user/view?id=<?php echo $author->id ?>"><?php echo $author->username ?></a>&nbsp;&nbsp;&nbsp;
        <?php echo Yii::$app->formatter->asRelativeTime($question->created_at); ?> 提问
        <span class="pull-right">
            <?php echo Attention::check($question->id); ?>
        </span>
    </p>
    <hr>
    <!--内容-->
    <div>
        <?php echo $question->body; ?>
    </div>
    <br>
    <!--标签-->
    <p>
        <?php foreach ($tags as $tag): ?>
            <a href="/tags/show?id=<?php echo $tag['id'] ?>" class="btn btn-primary btn-xs"><?php echo $tag['name'] ?></a>
        <?php endforeach; ?>
    </p>
    <hr>
    <!--回答列表-->
    <div class="comments">
        <?php if ($comments): ?>
            <?php foreach ($comments as $comment): ?>
                <div class="media">
                    <div class="media-left">
                        <?php if ($comment->best_answer): ?>
                            <div  class="best-answers"><span class="glyphicon glyphicon-bookmark"></span><br>采纳</div>
                        <?php endif; ?>
                        <?php if ($best_answer): ?>
                        <?php elseif (isset(Yii::$app->user->identity->id)): ?>
                            <?php if ($question->uid == Yii::$app->user->identity->id): ?>
                                <a href="/qa/adopt?qid=<?php echo $question->id ?>&answer_id=<?php echo $comment->id ?>" class="adopt-answers"><span class="glyphicon glyphicon-bookmark"></span><br>采纳</a>
                            <?php endif; ?>
                        <?php else: ?>
                            <div></div>
                        <?php endif; ?>
                    </div>
                    <div class="media-body">
                        <h5 class="media-heading" id="media-heading">
                            <a href="/user/view?id=<?php echo $comment->author->id; ?>" target="_blank"><?php echo $comment->author->username ?></a>&nbsp;&nbsp;<?php echo Yii::$app->formatter->asRelativeTime($comment->created_at) ?>
                            <span class="pull-right">
                                <a href="/user/view?id=<?php echo $comment->author->id; ?>" target="_blank">
                                    <img class="media-object" src="<?php echo $comment->author->avatar ? $comment->author->avatar : '../images/default/avatar.jpg' ?>" width="25" height="25">
                                </a>
                            </span>
                        </h5>
                        <div><?php echo $comment->body ?></div>
                        <small class="default-color"><a href="/comments/view?id=<?php echo $comment->id ?>">链接</a></small>
                    </div>
                </div>
                <hr>
            <?php endforeach; ?>
        <?php else: ?>
            0个答案
            <hr>
        <?php endif; ?>
    </div>
    <!--回答-->
    <?php if (!$is_comment): ?>
        <div class="add-comment" id="add-comment">
            <?php $form = ActiveForm::begin(['action' => '/comments/add?type=qa&id=' . $question->id]); ?>
            <?php echo $form->field($model_comment, 'body')->textarea(['rows' => 6, 'id' => 'ueditor', 'class' => ''])->label('撰写答案') ?>
            <div class="form-group">
                <?php echo Html::submitButton('提交回答', ['class' => 'btn btn-success']) ?>
            </div>
            <?php ActiveForm::end(); ?>
        </div>
    <?php endif; ?>

</div>
